<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    template="/layout/template.xhtml">

<ui:define name="body">

    <rich:panel>
        <f:facet name="header">Questionário</f:facet>

		<s:decorate id="nome" template="/layout/display.xhtml">
            <ui:define name="label">Nome</ui:define>
            <h:outputText value="#{questionarioHome.instance.nome}"/>
        </s:decorate>
        
        <s:decorate id="descricao" template="/layout/display.xhtml">
            <ui:define name="label">Descrição</ui:define>
            <h:outputText value="#{questionarioHome.instance.descricao}"/>
        </s:decorate>

        <s:decorate id="cliques" template="/layout/display.xhtml">
            <ui:define name="label">Cliques</ui:define>
            <h:outputText value="#{questionarioHome.instance.cliques}"/>
        </s:decorate>
        
        <s:decorate id="nivel" template="/layout/display.xhtml">
            <ui:define name="label">Nível</ui:define>
            <h:outputText value="#{questionarioHome.instance.nivel}"/>
        </s:decorate>

        <s:decorate id="dataCadastro" template="/layout/display.xhtml">
            <ui:define name="label">Data de Cadastro</ui:define>
            <h:outputText value="#{questionarioHome.instance.dataCadastro.time}"/>
        </s:decorate>

        <div style="clear:both"/>

    </rich:panel>

    <div class="actionButtons">

        <s:button view="/resources/QuestionarioEdit.xhtml"
                    id="edit"
                 value="Editar"
                 rendered="#{s:hasRole('Subgrupo') or permissao.meuQuestionario}"/>

        <s:button view="/resources/#{empty questionarioFrom ? 'QuestionarioList' : questionarioFrom}.xhtml"
                    id="done"
                 value="Concluído"/>
        
        <s:button view="/resources/Quiz.xhtml"
        			id="quiz"
        		 value="Quiz!"
              rendered="#{not empty usuario.id}"
           propagation="begin">
           
           <f:param name="questionarioId"
           		   value="#{questionarioHome.instance.id}"/>
           <f:param name="usuarioId"
           		   value="#{usuario.id}"/>
        </s:button>

    </div>

    <rich:tabPanel switchType="ajax">

    <rich:tab>
        <f:facet name="label">
            <h:panelGroup><h:graphicImage value="/img/manytoone.gif" style="vertical-align: middle; padding-right: 4px;"/>Categoria</h:panelGroup>
        </f:facet>
    <div class="association" id="categoriaParent">

        <h:outputText value="Não existe Categoria atrelada a este Questionário."
                   rendered="#{questionarioHome.instance.categoria == null}"/>

        <rich:dataTable var="_categoria"
                   value="#{questionarioHome.instance.categoria}"
                rendered="#{questionarioHome.instance.categoria != null}"
              rowClasses="odd,even"
                      id="categoriaTable">
            <h:column>
                <f:facet name="header">Nome</f:facet>
                <h:outputText value="#{_categoria.nome}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Descrição</f:facet>
                <h:outputText value="#{_categoria.descricao}"/>
            </h:column>
            <rich:column styleClass="action" style="text-align: center;">
                <f:facet name="header">Opções</f:facet>
                <s:link id="viewcategoria"
                     value="Ver"
                      view="/resources/Categoria.xhtml">
                    <f:param name="categoriaId"
                           value="#{_categoria.id}"/>
                </s:link>
            </rich:column>
        </rich:dataTable>

    </div>
    </rich:tab>

    <rich:tab>
        <f:facet name="label">
            <h:panelGroup><h:graphicImage value="/img/manytoone.gif" style="vertical-align: middle; padding-right: 4px;"/>Usuário</h:panelGroup>
        </f:facet>
    <div class="association" id="usuarioParent">

        <h:outputText value="Não existe usuário atrelado a este Questionário."
                   rendered="#{questionarioHome.instance.usuario == null}"/>

        <rich:dataTable var="_usuario"
                   value="#{questionarioHome.instance.usuario}"
                rendered="#{questionarioHome.instance.usuario != null}"
              rowClasses="odd,even"
                      id="usuarioTable">
            <h:column>
                <f:facet name="header">Nome</f:facet>
                <h:outputText value="#{_usuario.nome}"/>
            </h:column>
            <h:column>
                <f:facet name="header">E-mail</f:facet>
                <h:outputText value="#{_usuario.email}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Data de Cadastro</f:facet>
                <h:outputText value="#{_usuario.dataCadastro.time}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Status</f:facet>
                <h:outputText value="#{_usuario.status}"/>
            </h:column>
            <rich:column styleClass="action" style="text-align: center;">
                <f:facet name="header">Opções</f:facet>
                <s:link id="viewusuario"
                     value="Ver"
                      view="/resources/Usuario.xhtml">
                    <f:param name="usuarioId"
                           value="#{_usuario.id}"/>
                </s:link>
            </rich:column>
        </rich:dataTable>

    </div>
    </rich:tab>

    <rich:tab>
        <f:facet name="label">
            <h:panelGroup><h:graphicImage value="/img/onetomany.gif" style="vertical-align: middle; padding-right: 4px;"/>Questão</h:panelGroup>
        </f:facet>
    <h:form styleClass="association" id="questaoChildren">

        <h:outputText value="Não existe questão cadastrada."
                   rendered="#{empty questionarioHome.questao}"/>

        <rich:dataTable value="#{questionarioHome.questao}"
                       var="_questao"
                  rendered="#{not empty questionarioHome.questao}"
                rowClasses="odd,even"
                        id="questaoTable"
                      rows="20">
            <rich:column sortBy="#{_questao.questao}">
                <f:facet name="header">Enunciado</f:facet>
                <h:outputText value="#{_questao.questao}"/>
            </rich:column>
            <rich:column sortBy="#{_questao.acertos}">
                <f:facet name="header">Acertos</f:facet>
                <h:outputText value="#{_questao.acertos}"/>
            </rich:column>
            <rich:column sortBy="#{_questao.erros}">
                <f:facet name="header">Erros</f:facet>
                <h:outputText value="#{_questao.erros}"/>
            </rich:column>
            <rich:column sortBy="#{_questao.tipoQuestao}">
                <f:facet name="header">Tipo da Questão</f:facet>
                <h:outputText value="#{_questao.tipoQuestao}"/>
            </rich:column>
            <rich:column style="text-align: center;">
                <f:facet name="header">Opções</f:facet>
                <s:link id="selectquestao"
                     value="Selecionar"
                      view="/resources/Questao.xhtml">
                    <f:param name="questaoId"
                            value="#{_questao.id}"/>
                    <f:param name="questaoFrom" value="Questionario"/>
                </s:link>
            </rich:column>
        </rich:dataTable>
        
        <br clear="left"/>
        
        <rich:datascroller id="dataScrollerQuestao" for="questaoTable" renderIfSinglePage="false"/>

    </h:form>

    <div class="actionButtons">
        <s:button
               value="Cadastrar Questão"
                view="/resources/QuestaoEdit.xhtml"
            rendered="#{s:hasRole('Subgrupo') or usuario.id eq questionarioHome.instance.usuario.id}">
            <f:param name="questionarioId"
                    value="#{questionarioHome.instance.id}"/>
            <f:param name="questaoFrom" value="Questionario"/>
        </s:button>
    </div>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
